package com.ruoyi.web.controller.wxpay;

import java.util.List;

import com.ruoyi.weixin.vo.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.weixin.domain.KssCourses;
import com.ruoyi.weixin.service.IKssCoursesService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程表Controller
 * 
 * @author cfw
 * @date 2021-10-07
 */
@Controller
@RequestMapping("/weixin/courses")
public class KssCoursesController extends BaseController
{
    private String prefix = "weixin/courses";

    @Autowired
    private IKssCoursesService kssCoursesService;

    /**
     * 跳转到课程首页
     *
     * @return
     */
    @RequiresPermissions("weixin:courses:view")
    @GetMapping()
    public String courses() {
        return prefix + "/show";
    }

    /**
     * 加载列表
     *
     * @return
     */
    @RequestMapping("/loadcourse")
    @ResponseBody
    public R test() {
        KssCourses kssCourses = new KssCourses();
        List<KssCourses> list = kssCoursesService.selectKssCoursesList(kssCourses);
        return R.ok().data("courses", list);
    }

    /**
     * 跳转课程明细
     *
     * @return
     */
    @GetMapping("coursedetail/{id}")
    public String coursedetail(@PathVariable("id") String id, ModelMap modelMap) {
        // 1：根据课程ID查询课程信息
        KssCourses course = kssCoursesService.selectKssCoursesById(id);
        // 2：把课程信息放入到作用域中
        modelMap.put("course", course);
        // 3：返回课程明细的视图
        return prefix + "/coursedetail";
    }











    /**
     * 查询课程表列表
     */
    @RequiresPermissions("weixin:courses:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(KssCourses kssCourses)
    {
        startPage();
        List<KssCourses> list = kssCoursesService.selectKssCoursesList(kssCourses);
        return getDataTable(list);
    }

    /**
     * 导出课程表列表
     */
    @RequiresPermissions("weixin:courses:export")
    @Log(title = "课程表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(KssCourses kssCourses)
    {
        List<KssCourses> list = kssCoursesService.selectKssCoursesList(kssCourses);
        ExcelUtil<KssCourses> util = new ExcelUtil<KssCourses>(KssCourses.class);
        return util.exportExcel(list, "课程表数据");
    }

    /**
     * 新增课程表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存课程表
     */
    @RequiresPermissions("weixin:courses:add")
    @Log(title = "课程表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(KssCourses kssCourses)
    {
        return toAjax(kssCoursesService.insertKssCourses(kssCourses));
    }

    /**
     * 修改课程表
     */
    @GetMapping("/edit/{courseid}")
    public String edit(@PathVariable("courseid") String courseid, ModelMap mmap)
    {
        KssCourses kssCourses = kssCoursesService.selectKssCoursesById(courseid);
        mmap.put("kssCourses", kssCourses);
        return prefix + "/edit";
    }

    /**
     * 修改保存课程表
     */
    @RequiresPermissions("weixin:courses:edit")
    @Log(title = "课程表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(KssCourses kssCourses)
    {
        return toAjax(kssCoursesService.updateKssCourses(kssCourses));
    }

    /**
     * 删除课程表
     */
    @RequiresPermissions("weixin:courses:remove")
    @Log(title = "课程表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(kssCoursesService.deleteKssCoursesByIds(ids));
    }
}
